package bidgetserver;

import java.io.IOException;
//import java.util.Date;
import java.util.List;
//import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;
//import com.google.appengine.api.users.User;
//import com.google.appengine.api.users.UserService;
//import com.google.appengine.api.users.UserServiceFactory;

import bidgetserver.Product;
import bidgetserver.PMF;

public class ClearHistory extends HttpServlet {
    //private static final Logger log = Logger.getLogger(SignGuestbookServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        String userName = req.getParameter("userName");

        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from "+Product.class.getName()+" where author == '"+userName+"'";
        query+=" && flag == false";
        
        List<Product> userProduct = (List<Product>) pm.newQuery(query).execute();

        try{
        	for (int i=0; i<userProduct.size(); i++){
        		pm.deletePersistent(userProduct.get(i));
			}	
        }
        finally{
        	pm.close();
        }

    }
}
